package com.henu.engineer.controller.teacher

import com.alibaba.fastjson.JSONObject
import com.henu.engineer.StringUtils
import com.henu.engineer.service.AchieveDegreeService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 * @author noexcept
 * @since 9/25/2021 11:42 PM
 */
@RestController
@RequestMapping("/tc")
class AchieveDegreeTCController {

    @Autowired
    lateinit var achieveDegreeService: AchieveDegreeService

    /**
     * 某课程所有学生所有目标的达成度
     */
    @GetMapping("/courseGoalAchieved")
    fun getCourseGoalAchieved(courseId: String?): String {
        val res = JSONObject()
        if (StringUtils.isEmpty(courseId)) {
            res["code"] = 1
            res["msg"] = "课程id缺失"
            return res.toJSONString()
        }
        res["code"] = 0
        res["msg"] = "success"
        res["res"] = achieveDegreeService.getCourseGoalAchieved(courseId!!)
        return res.toJSONString()
    }

    /**
     * 课程所有学生课程目标总达成度
     */
    @GetMapping("/courseGoalSumAchieved")
    fun getCourseGoalSumAchieved(courseId: String?): String {
        val res = JSONObject()
        if (StringUtils.isEmpty(courseId)) {
            res["code"] = 1
            res["msg"] = "课程id缺失"
            return res.toJSONString()
        }
        res["code"] = 0
        res["msg"] = "success"
        res["res"] = achieveDegreeService.getCourseGoalSumAchieved(courseId!!)
        return res.toJSONString()
    }

    /**
     * 课程所有学生达成度
     */
    @GetMapping("/courseAchieved")
    fun getCourseAchieved(courseId: String?): String {
        val res = JSONObject()
        if (StringUtils.isEmpty(courseId)) {
            res["code"] = 1
            res["msg"] = "课程id缺失"
            return res.toJSONString()
        }
        res["code"] = 0
        res["msg"] = "success"
        res["res"] = achieveDegreeService.getCourseAchieved(courseId!!)
        return res.toJSONString()
    }
}